package com.chookss.tiku.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chookss.R;
import com.chookss.tools.Utils;
import com.chookss.video.entity.VideoCate;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目名：  ListViewLinkage
 * 描述：    左侧Adapter
 */
public class CateRightChildAdapter extends BaseAdapter {
    //标题
    private List<VideoCate> leftStr;
    private  ArrayList<String> codes;
    //标志
    private LayoutInflater inflater;

    public CateRightChildAdapter(Context mContext, ArrayList<String> codes, List<VideoCate> leftStr) {
        this.leftStr = leftStr;
        this.codes = codes;
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return leftStr.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            //加载
            convertView = inflater.inflate(R.layout.item_video_cate_right_in_linewrap, parent, false);
            //绑定
            holder.tcCatesRight = (TextView) convertView.findViewById(R.id.tcCatesRight);
            holder.tvNum = (TextView) convertView.findViewById(R.id.tvNum);
            holder.tvPlayCount = (TextView) convertView.findViewById(R.id.tvPlayCount);
            holder.tvLikeCount = (TextView) convertView.findViewById(R.id.tvLikeCount);
            holder.ll_item_bg = (LinearLayout) convertView.findViewById(R.id.ll_item_bg);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //设置数据
        holder.tcCatesRight.setText(leftStr.get(position).name);
        holder.tvNum.setText(Utils.changeNumber(leftStr.get(position).totalNum) +"个视频");
        holder.tvPlayCount.setText(""+Utils.changeNumber(leftStr.get(position).playCount));
        holder.tvLikeCount.setText(""+Utils.changeNumber(leftStr.get(position).likeCount));
        if(codes.contains(leftStr.get(position).code)){
            holder.ll_item_bg.setBackgroundResource(R.color.video_cate);
        }else{
            holder.ll_item_bg.setBackgroundResource(R.color.white);
        }
        return convertView;
    }

    class ViewHolder {
        private TextView tcCatesRight,tvNum,tvPlayCount,tvLikeCount;
        private LinearLayout ll_item_bg;
    }

}